package android.bluebox.model;


public class PasswordCrypto {

	private String password;
	private String strMD5;
	private int iterationCount = 2020;

	private Crypto3 blueCrypto; 

	public void init(String password) {

		strMD5 = StaticBox.dbBox.getSystemHash();
		setPassword(password);
	}

	// Set new password for PasswordCrypto and re-init.

	public void setPassword(String password) {
		this.password = password;
		blueCrypto = new Crypto3(this.password, StaticBox.getSalt(), iterationCount); 
	}

	// Create new file PWDMD5

	public void firstInit(String password) {
		String pwdMD5 = Crypto3.createMD5(password);
		this.password = password;
		StaticBox.dbBox.updateSystemHash(pwdMD5);
		blueCrypto = new Crypto3(this.password, StaticBox.getSalt(), iterationCount); 
	}


	public boolean checkPassword(String password) {
		return (Crypto3.createMD5(password).equals(strMD5));
	}

	public String encrypt(String str) {
		return blueCrypto.encrypt(str);
	}

	public String decrypt(String str) {
		return blueCrypto.decrypt(str);
	}
}
